# _*_ coding: utf-8 _*_
# @Time : 2024-01-23 22:22
# @Author : wf
import openpyxl.worksheet.worksheet
from openpyxl import Workbook
from openpyxl.chart import LineChart, Reference

wb = Workbook()
ws: openpyxl.worksheet.worksheet.Worksheet = wb.active

# 准备数据
rows = [
    ['月份', '桃子', '西瓜', '龙眼'],
    [1, 38, 28, 29],
    [2, 52, 21, 35],
    [3, 39, 20, 69],
    [4, 51, 29, 41],
    [5, 39, 39, 31],
    [6, 30, 41, 39],
]
for row in rows:
    ws.append(row)

c1 = LineChart()
c1.title = '水果销量折线图'
c1.style = 13
c1.y_axis.title = '销量'
c1.x_axis.title = '月份'

ref = Reference(ws, min_row=1, max_row=7, min_col=2, max_col=4)
c1.add_data(ref, titles_from_data=True)
s0 = c1.series[0]
s0.marker.symbol = 'triangle'
s0.marker.graphicalProperties.solidFill = "FF0000"  # 填充颜色
s0.marker.graphicalProperties.line.solidFill = "0000FF"  # 边框颜色

s1 = c1.series[1]
s1.graphicalProperties.line.solidFill = "00AAAA"
s1.graphicalProperties.line.dashStyle = "sysDot"  # 线条点状样式
s1.graphicalProperties.line.width = 80000  # 线条大小，最大20116800EMUs

s2 = c1.series[2]  # 采用默认设置
s2.smooth = True  # 线条平滑

ws.add_chart(c1, "A8")  # 图表位置

wb.save("test6.xlsx")
